
*************REPLICATION DO FILE***********
cd "/Users/lauragarciamontoya/Dropbox/0 War and Participation/2022/REPLICATION FILES HARVARD DATAVERSE/"


*****Figure 1
use "data_events_replication", replace

keep if year>=1984

graph bar (sum) killing attempt, over(year, label(angle(90))) legend( label(1 "Assassinations") label(2 "Failed Killing Attempts") position(bottom)) ytitle("Total by Year")  graphregion(color(white)) bar(1, color(black)) bar(2, color(gs8))

	
*****Figure 2 (Map)
use "data_for_map", clear

spmap killing_dummy using "Coordenadas.dta", id(_ID) 


******TABLES IN PAPER			
use panel_short_rest_politicians_final, clear

xtset codemun t

*RESTRICTS TABLE 1 TO ONLY DURING CIVIL WAR
keep if t<10


********************************************
******************** TABLE 1 ***************
********************************************

*Bivariate only (1)
xtreg turnout_alc treatment_rest if (ln_pop!=. & urban_rate!=.), vce(cluster codemun) 

*Bivariate + election effects (2)
xtreg turnout_alc treatment_rest i.t if (ln_pop!=. & 	urban_rate!=.), vce(cluster codemun) 

*Bivariate + Dept FE Restricted (3)
xtreg turnout_alc treatment_rest i.cod_dpto i.t if (ln_pop!=. & urban_rate!=.),  vce( cluster codemun)

* Dept FE Restricted  + controls 1 (4)
xtreg turnout_alc treatment_rest i.cod_dpto i.t ln_pop urban_rate if (ln_pop!=. & urban_rate!=.),  vce( cluster codemun) 

* Dept FE Restricted  + controls 2 (5)
xtreg turnout_alc treatment_rest i.cod_dpto i.t ln_pop urban_rate y_corr acc_subversivas if (ln_pop!=. & urban_rate!=.),  vce( cluster codemun) 

********************************************
******************** TABLE 2 ***************
********************************************


global treatments treatment_office_rest treatment_cand_rest

foreach t of global treatments{

*Bivariate restricted (1)
xtreg turnout_alc `t' if (ln_pop!=. & 	urban_rate!=.), vce( cluster codemun) 

*Bivariate restricted + election fixed effects (2)
xtreg turnout_alc `t' i.t if (ln_pop!=. & 	urban_rate!=.), vce( cluster codemun) 

*Bivariate restricted + election fixed effects + Dept FE Restricted (3)
xtreg turnout_alc `t' i.cod_dpto i.t if (ln_pop!=. & 	urban_rate!=.), vce( cluster codemun) 

*Bivariate restricted + election fixed effects + Dept FE Restricted + controls (4)
xtreg turnout_alc `t' ln_pop urban_rate i.cod_dpto i.t ln_pop urban_rate, vce( cluster codemun) 


*Bivariate restricted + election fixed effects + Dept FE Restricted + controls 2 (5)
xtreg turnout_alc `t' ln_pop urban_rate i.cod_dpto i.t ln_pop urban_rate y_corr acc_subversivas if (ln_pop!=. & 	urban_rate!=.), vce( cluster codemun) 

}				

********************************************
******************** TABLE 3 ***************
********************************************

gen AUC=0
replace AUC=1 if tactof_AUC>=1

gen FARC=0
replace FARC=1 if tactof_FARC>=1

gen ELN=0
replace ELN=1 if tactof_ELN>=1

gen DESC=0
replace DESC=1 if tactof_DES>=1


gen any_armed_actor=0
replace any_armed_actor=1 if AUC==1 | ELN==1 | FARC==1 	| DESC==1
	

****Violent Presence = 1	
*Bivariate Only (1)
xtreg turnout_alc treatment_rest if (ln_pop!=. & urban_rate!=.) & any_armed_actor==1 ,  vce( cluster codemun)
		
*Bivariate + election (2)
xtreg turnout_alc treatment_rest i.t if (ln_pop!=. & urban_rate!=.)  & any_armed_actor==1,  vce( cluster codemun)
		
*Bivariate + election + Dept FE (3)
capture noisily xtreg turnout_alc treatment_rest i.cod_dpto i.t if (ln_pop!=. & urban_rate!=.)  & any_armed_actor==1,  vce( cluster codemun) 

*Bivariate + election + Dept FE + controls (4)
capture noisily xtreg  turnout_alc treatment_rest ln_pop urban_rate i.cod_dpto i.t if any_armed_actor==1,  vce( cluster codemun)
			

****Violent Presence = 0 	
*Bivariate Only (1)
xtreg turnout_alc treatment_rest if (ln_pop!=. & urban_rate!=.) & any_armed_actor==0,  vce( cluster codemun)
		
*Bivariate + election (2)
xtreg turnout_alc treatment_rest i.t if (ln_pop!=. & urban_rate!=.) & any_armed_actor==0,  vce( cluster codemun)
	
*Bivariate + election + Dept FE (3)
capture noisily xtreg turnout_alc treatment_rest i.cod_dpto i.t if (ln_pop!=. & urban_rate!=.) & any_armed_actor==0,  vce( cluster codemun) 


*Bivariate + election + Dept FE (3)*Dept FE + controls (4)
capture noisily xtreg  turnout_alc treatment_rest ln_pop urban_rate i.cod_dpto i.t if any_armed_actor==0,  vce( cluster codemun)


********************************************
******************** TABLE 4 ***************
********************************************


*****2019 ELECTIONS
use "post_conflict_2019", clear

*Bivariate Only (1)
reg turnout_alc treatment_restricted if (ln_pop!=. & urban_rate!=.), vce(cluster codemun) 


* Bivariate + Dept FE (2)
reg turnout_alc treatment_rest i.cod_dpto if (ln_pop!=. & urban_rate!=.), vce(cluster codemun) 


* Dept FE Restricted  + controls 1 (3)
reg turnout_alc treatment_restricted i.cod_dpto ln_pop urban_rate if (ln_pop!=. & urban_rate!=.),  vce( cluster codemun) 


* Dept FE Restricted  + controls 2 (4)
reg turnout_alc treatment_restricted i.cod_dpto ln_pop urban_rate y_corr acc_subversivas if (ln_pop!=. & urban_rate!=.),  vce( cluster codemun) 


*****2023 ELECTIONS
use "post_conflict_2023", clear
*Bivariate Only (1)
reg turnout_alc treatment_restricted if (ln_pop!=. & urban_rate!=.), vce(cluster codemun) 

* Bivariate + Dept FE (2)
reg turnout_alc treatment_rest i.cod_dpto if (ln_pop!=. & urban_rate!=.), vce(cluster codemun) 


* Dept FE Restricted  + controls 1 (3)
reg turnout_alc treatment_restricted i.cod_dpto ln_pop urban_rate if (ln_pop!=. & urban_rate!=.),  vce( cluster codemun)


* Dept FE Restricted  + controls 2 (4)
reg turnout_alc treatment_restricted i.cod_dpto ln_pop urban_rate y_corr acc_subversivas if (ln_pop!=. & urban_rate!=.),  vce( cluster codemun) 




**************************************
*****Figure 3 - Event Study***********
**************************************
use panel_full_final, clear

*Prepares data for event studies
xtset codemun year

bysort codemun: egen tattempts=sum(any_att)
bysort codemun: egen tkills=sum(any_kills)

keep if (tkills!=. & tkills!=0) | (tattempts!=. & tattempts!=0)

keep if year<2019

gen year2=1 if year==1988
replace year2=2 if year==1990
replace year2=3 if year==1992
replace year2=4 if year==1994
replace year2=5 if year==1997
replace year2=6 if year==2000
replace year2=7 if year==2003
replace year2=8 if year==2007
replace year2=9 if year==2011
replace year2=10 if year==2015

drop if year2==.

xtset codemun year2

gen treatmentall_year = year2 if treatment_all==1
bysort codemun: egen first_treatedall=min(treatmentall_year)
drop treatmentall_year
gen ry_all=year2 - first_treatedall

 gen never_treated_all= (first_treatedall==.) 		

***loops to create time variable, drops using t-1 as baseline. 
forvalues k = 11(-1)2 {
           gen tall_`k' = ry_all == -`k'
		   label var tall_`k' "-`k'"
        }
		
        forvalues k = 0/11 {
             gen tall`k' = ry_all == `k'
			   label var tall`k' "+`k'"
        }
		
gen tall_1=0
label var tall_1 "-1"			

			
eventstudyinteract turnout_alc tall_4 tall_3 tall_2 tall0 tall1 tall2 tall3 tall4 tall5 tall6, cohort(first_treatedall) control_cohort(never_treated_all) absorb(i.year2 i.codemun) vce(cluster codemun) 
matrix C = e(b_iw)
mata st_matrix("A",sqrt(diagonal(st_matrix("e(V_iw)"))))
matrix C = C \ A' 


matrix new_C1 = (C[1,1] \ C[2,1])

matrix new_C2 = (C[1,2] \ C[2,2])

matrix new_C3 = (C[1,3] \ C[2,3])

matrix new_C4 = (0 \ 0 )

matrix new_C5 = (C[1,4] \ C[2,4])

matrix new_C6 = (C[1,5] \ C[2,5])

matrix new_C7 = (C[1,6] \ C[2,6])

matrix new_C8 = (C[1,7] \ C[2,7])

matrix new_C9 = (C[1,8] \ C[2,8])

matrix new_C10 = (C[1,9] \ C[2,9])

matrix new_C11 = (C[1,10] \ C[2,10])


matrix new_all = new_C1 , new_C2 , new_C3 , new_C4 , new_C5 , new_C6 , new_C7 , new_C8 , new_C9 , new_C10 , new_C11

matrix list new_all

matrix colnames new_all = tall_4 tall_3 tall_2 tall_1 tall0 tall1 tall2 tall3 tall4 tall5 tall6

matrix rownames new_all = r1 c1

coefplot matrix(new_all[1]), se(new_all[2]) vertical xline(4) bgcolor(white) graphregion(color(white))


